package org.algorithm.wE1.字符串;

import java.util.HashMap;
import java.util.Map;

/**
 * @Date 2022/2/23
 * @Link {https://leetcode-cn.com/problems/excel-sheet-column-number/}
 */
public class Excel表列序号 {

    public static void main(String[] args) {
        String s = "FXSHRXW";
        System.out.println(titleToNumber(s));
    }
    public static int titleToNumber(String s) {
         char[] chars = s.toCharArray();
        Map<String,Integer> map = new HashMap<>(16);
       char a = 'A';
       char z = 'Z';
        for (int i = a; i <=z ; i++) {
            map.put(String.valueOf((char)i),i-64);
        }
        long ss = (long) Math.pow(26,chars.length);
        int num = 0;
        for (int i = 0; i <chars.length ; i++) {
            ss/=26;
             num += map.get(String.valueOf(chars[i]))*ss;
        }

        return  num;
    }
}
